package IC.videopatrol.controller;

import IC.common.core.domain.R;
import com.ic.domain.response.FaceDetectionResponse;
import IC.videopatrol.service.FaceRecognitionservice;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.ic.domain.response.FaceDetectionResponse2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


@RestController
public class FaceRecognitionController {
    @Autowired
    private FaceRecognitionservice faceRecognitionService;

    /**
     * 新增实有人口人脸
     *
     * @param imageBase64
     * @param
     * @return
     */
    @PostMapping("/recognize-face")
    public R<?> recognizeFace(@RequestParam(value = "imageBase64") String imageBase64) throws IOException {
        faceRecognitionService.recognizeFace(imageBase64);
        return R.ok();
    }



    /**
     * 新增布控人脸
     */
    @PostMapping("/defense-face")
    public R<String> defenseface(@RequestParam(value = "imageBase64") String imageBase64,@RequestParam(value = "subject") String subject) throws IOException {
        String defenseface = faceRecognitionService.defenseface(imageBase64, subject);
        return R.ok(defenseface);
    }

    /**
     * 删除模块
     *
     * @param subject
     * @return
     */
    @DeleteMapping("/delrecognize-module")
    public R<?> deleteFaceBySubject(@RequestParam(value = "subject") String subject) {
        faceRecognitionService.deleteFaceBySubject(subject);
        return R.ok();
    }

    /**
     * 删除人脸
     */
    @DeleteMapping("/delrecognize-face")
    public R<?> deleteFace(@RequestParam(value = "subject") String subject, @RequestParam(value = "imageId") String imageId) {
        faceRecognitionService.deleteFaceByImageId(subject, imageId);
        return R.ok();
    }

    /**
     * 人像识别
     */
    @PostMapping("/recognize-faceDetect")
    public R<FaceDetectionResponse> recognizeFaceContrast(@RequestParam("image") String imageBase64) {

        try {
            return R.ok(faceRecognitionService.faceDetect(imageBase64));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }


    /**
     * 人像对比
     *
     * @param imageBase64
     * @throws Exception
     */
    @PostMapping("/imgContrast")
    public R<FaceDetectionResponse2> imgContrast(@RequestParam("image")String imageBase64) throws IOException {
         return R.ok(faceRecognitionService.imgContrast(imageBase64));
    }


}
